{% extends 'app01/base.html' %}
{% block active_project_manage %} class="active"{% endblock %}
{% block active_case_manage %}{% endblock %}
{% block sub_header %}项目管理页面{% endblock %}
{% block search %}
    <form class="form-inline"
          action="{% block search_url %}{% url 'projectManage:search_project' %}{% endblock search_url %}"
          id="form_Condition" method="get">
        {% csrf_token %}
        <label for="startTime">创建起始：</label>
        <input type="date" class="form-control input-sm" id="start_date" name="start_date"
                {% block search_start %}{% endblock %}
               style="width: 165px;margin-right: 5px">
        <label for="endTime">创建结束：</label>
        <input type="date" class="form-control input-sm" id="end_date" name="end_date"
                {% block search_end %}{% endblock %} style="width: 165px;margin-right: 5px">
        {% block search_condition %}<label for="project_name">项目名称：</label>
            <input class="form-control" id="project_name" name="project_name"
                    {% block project_name %}{% endblock %} style="width: 120px;margin-right: 5px">{% endblock %}
        <label for="project_bu">所属BU：</label>
                    <input class="form-control" id="project_bu" name="project_bu"
                            {% block project_bu %}{% endblock %} style="width: 120px;margin-right: 5px">
        <br/>
        <br/>
        <div class="btn-group">
            <button type="button" class="btn btn-secondary btn-sm" id="btn_Clear" onclick="function back_to_index() {
                    window.location.href='{% block back_url %}{% url "projectManage:project_manage" %}{% endblock %}';
                    }
                    back_to_index()">清空
            </button>
            <button type="submit" class="btn btn-info btn-sm" id="btn_Search">查询
            </button>
        </div>
    </form>
{% endblock %}

{% block table %}
    <table class="table table-striped table-bordered table-responsive">
        <thead>
        <tr>
            <th style="width: 10px"><input type="checkbox"></th>
            <th style="width: 50px">序号</th>
            <th nowrap="nowrap">项目名称</th>
            <th nowrap="nowrap">描述</th>
            <th nowrap="nowrap">更新时间</th>
            <th nowrap="nowrap">创建时间</th>
            <th nowrap="nowrap">所属BU</th>
            <th nowrap="nowrap">备注</th>
            <th hidden="hidden">ID</th>
            <th nowrap="nowrap">操作</th>
        </tr>
        </thead>
        <tbody>
        {% for project in pages %}
            <tr style="font-size: 10px">
                <td><input type="checkbox" value="{{ project.id }}"></td>
                <td>{{ forloop.counter }}</td>
                <td>{{ project.project_name }}</td>
                <td>{{ project.project_describe }}</td>
                <td>
                    {% if project.update_time %}
                        {{ project.update_time|date:'Y-m-d H:i' }}
                    {% endif %} </td>
                <td>{{ project.create_time|date:'Y-m-d H:i' }}</td>
                <td>{{ project.BU }}</td>
                <td>{{ project.remarks }}</td>
                <td hidden="hidden">{{ project.id }}</td>
                <td nowrap="nowrap">

{# TODO 修改和删除待完成 #}

                    <button data-toggle="modal" data-target=".bs-example-modal-lg"
                                            onclick="showDialog(this)">修改
                                    </button>
                    <a href="{% block delete_url %}{% url 'projectManage:project_delete' project.id %}{% endblock %}"
                       id="{{ project.id }}" onclick="return deleteJob()">删除</a>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}
{% block button %}
<div class="btn-group" role="group" aria-label="Basic example">
                    <button type="button" data-toggle="modal" data-target="#createProjectModal" class="btn btn-primary">新增</button>
{#                    <button type="button" class="btn btn-primary" disabled>批量编辑</button>#}
{#                    <button type="button" class="btn btn-primary" disabled>批量删除</button>#}
{#                    <button type="button" class="btn btn-primary" onclick="window.location.href='{% block export_url %}{% url "projectManage:export_project" %}{% endblock export_url %}'">导出</button>#}
                    <button type="button" class="btn btn-primary" onclick="window.location.reload()">刷新</button>
                </div>

{% endblock %}
{% block create_modal %}
    <div class="modal fade" id="createProjectModal" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel"
                         aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">项目新增</h4>
                                </div>
                                <form class="form-inline" action="
                                        {% block create_case_url %}{% url 'projectManage:create_project' %}{% endblock create_case_url %}"
                                      method="post">
                                    {% csrf_token %}
                                    <div class="modal-body">
                                        <label for="project_name">项目名称：</label>
                                        <input name="project_name" class="form-control input_for_modal" type="text"
                                               id="project_name" required>
                                        <label for="create_time">创建时间：</label>
                                        <input name="create_time" class="form-control input_for_modal" type="datetime-local"
                                               id="create_time">
                                        <br>
                                        <label for="project_describe">描述：</label>
                                        <textarea id="project_describe" style="height: 96px; width: 544px;" name="project_describe" class="form-control input_for_modal case_steps"></textarea>

                                        <label style="width: 70px" for="BU">所属BU：</label>
                                        <input name="BU" class="form-control input_for_modal" type="text"
                                               id="BU">
                                        <label style="width: 70px" for="remarks">备注：</label>
                                        <input name="remarks" style="width: 191px;" class="form-control input_for_modal" type="text"
                                               id="remarks">
                                    </div>
                                <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                        <button type="submit" class="btn btn-primary">提交</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
{% endblock %}
{% block edit_modal %}
    <div class="modal fade" id="EditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="EditModalLabel">项目修改</h4>
                </div>
                <form class="form-inline"
                      action="{% block edit_url %}{% url 'projectManage:edit_project' %}{% endblock %}" method="post">
                    {% csrf_token %}
                    <div class="modal-body">
                        <label style="width: 70px" for="project_id">ID：</label>
                        <input name="project_id" class="form-control input_for_modal project_id" type="text"
                               id="project_id" readonly>
                        <label for="project_name" style="width: 70px;">项目名称：</label>
                        <input name="project_name" class="form-control input_for_modal project_name"
                               type="text"
                               id="project_name" required>
                        <label for="project_describe" style="width: 70px">描述：</label>
                        <textarea name="project_describe" style="width: 469px; height: 82px;" class="form-control input_for_modal project_describe"
                                  id="project_describe"></textarea>
                        <label for="BU" style="width: 70px">所属BU：</label>
                        <input name="BU" class="form-control input_for_modal BU"
                               type="text" id="BU">
                        <label style="width: 70px" for="create_time">创建时间：</label>
                        <input name="create_time" class="form-control input_for_modal create_time"
                               type="datetime-local" style="width: 193px;" id="create_time" readonly>
                        <label style="width: 70px" for="remarks">备注：</label>
                        <input name="remarks" class="form-control input_for_modal remarks" type="text"
                               id="remarks">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}
{% block edit_script %}
    <script>
        function showDialog(obj) {
            $('#EditModal').modal('show');
            var tds = $(obj).parent().parent().find('td');
            $(".project_id").val($(tds.eq(8)).text());

            $(".project_name").val($(tds.eq(2)).text());
            $(".project_describe").val($(tds.eq(3)).text());
            $(".BU").val($(tds.eq(6)).text());
            var create_time = $(tds.eq(5).text()).selector
            var create_time1 = create_time.split(' ').join('T')
            $(".create_time").val(create_time1);
            $(".remarks").val($(tds.eq(7)).text());
        }

        function deleteJob() {
            return confirm("删除项目将会删除关联的用例，确定删除吗?");
        }

    </script>
{% endblock %}